﻿@model ZSZ.AdminWeb.Models.House.HouseEditGet
@{
    ViewBag.Title = "Edit";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<form id="formData">
    @*<input type="hidden" value="@ViewBag.TypeId" name="typeId" />*@
    <input type="hidden" value="@Model.House.Id" name="HouseId" />
    <div class="row cl">
        <div class="col-xs-12 col-sm-4">
            <label for="quyu"><span style="color:red">*</span>区域</label>
            <select id="quyu" name="Region">
                @foreach (var item in Model.Regions)
                {
                    if (item.Id == Model.House.RegionId)
                    {
                        <option value="@item.Id" selected="selected">@item.Name</option>
                        continue;
                    }
                    <option value="@item.Id">@item.Name</option>
                }
            </select>
        </div>
        <div class="col-xs-12 col-sm-4">
            <label for="xiaoqu"><span style="color:red">*</span>小区</label>
            <select name="CommunityId" id="Community"></select>
        </div>
        <div class="col-xs-12 col-sm-4">
            <label for="fangxing"><span style="color:red">*</span>房型</label>
            <select id="fangxing" name="RoomTypeId">
                @foreach (var item in Model.FangXing)
                {
                    if (item.Id == Model.House.RoomTypeId)
                    {
                        <option value="@item.Id" selected="selected">@item.Name</option>
                        continue;
                    }
                    <option value="@item.Id">@item.Name</option>
                }
            </select>
        </div>
    </div>
    <div class="row cl">
        <div class="col-xs-12 col-sm-8">
            <label for="dizhi"><span style="color:red">*</span>地址</label>
            <input id="dizhi" value="@Model.House.Address" name="address" type="text" />
        </div>
        <div class="col-xs-12 col-sm-4">
            <label for="yuezuJin"><span style="color:red">*</span>月租金</label>
            <input id="yuezuJin" name="MonthRent" value="@Model.House.MonthRent" type="text" />元
        </div>
    </div>
    <div class="row cl">
        <div class="col-xs-12 col-sm-4">
            <label for="zhuangtai"><span style="color:red">*</span>状态</label>
            <select id="zhuangtai" name="StatusId">
                @foreach (var item in Model.Zhuang)
                {
                    if (item.Id == Model.House.StatusId)
                    {
                        <option value="@item.Id" selected="selected">@item.Name</option>
                        continue;
                    }
                    <option value="@item.Id">@item.Name</option>
                }
            </select>
        </div>
        <div class="col-xs-12 col-sm-4">
            <label for="mianji"><span style="color:red">*</span>面积</label>
            <input id="mianji" name="Area" value="@Model.House.Area" />平米
        </div>
        <div class="col-xs-12 col-sm-4">
            <label for="zhuangtai"><span style="color:red">*</span>装修</label>
            <select id="zhuangtai" name="DecorateStatusId">
                @foreach (var item in Model.ZhuangZhuang)
                {
                    if (item.Id == Model.House.DecorateStatusId)
                    {
                        <option value="@item.Id" selected="selected">@item.Name</option>
                        continue;
                    }
                    <option value="@item.Id">@item.Name</option>
                }
            </select>
        </div>
    </div>
    <div class="row cl">
        <div class="col-xs-12 col-sm-4">
            <label for="louceng"><span style="color:red">*</span>楼层</label>
            <input type="text" id="louceng" style="width:50px" name="TotalFloorCount" placeholder="楼数" />
            <input type="text" name="FloorIndex" style="width:50px" placeholder="层数" />
        </div>
        <div class="col-xs-12 col-sm-4">
            <label for="chaoxiang"><span style="color:red">*</span>朝向</label>
            <input type="text" id="chaoxiang" name="chao" />
        </div>
        <div class="col-xs-12 col-sm-4">
            <label for="kanfang"><span style="color:red">*</span>可看房时间</label>
            <input type="datetime" id="kanfang" name="LookableDateTime" value="@Model.House.LookableDateTime" />
        </div>
    </div>
    <div class="row cl">
        <div class="col-xs-12 col-sm-4">
            <label for="ruzhu"><span style="color:red">*</span>可入住时间</label>
            <input type="datetime" id="ruzhu" name="CheckInDateTime" value="@Model.House.CheckInDateTime" />
        </div>
        <div class="col-xs-12 col-sm-4">
            <label for="yezhuname"><span style="color:red">*</span>业主姓名</label>
            <input id="yezhuname" name="OwnerName" value="@Model.House.OwnerName" />
        </div>
        <div class="col-xs-12 col-sm-4">
            <label for="yezhushouji"><span style="color:red">*</span>业主手机号</label>
            <input id="yezhushouji" name="OwnerPhoneNum" value="@Model.House.OwnerPhoneNum" />
        </div>
    </div>
    <label for="mianshu">房源描述</label>
    <textarea name="Description" id="mianshu" cols="100" rows="10">@Model.House.Description</textarea>
    <br /><br />
    <label for="peitai">配套设施：</label><br />
    @foreach (var item in Model.Attachmentes)
    {
        if (Model.House.AttachmentIds.Any(s=>s==item.Id))
        {
            <input type="checkbox" name="AttachmentIds" checked="checked" value="@item.Id" />@item.Name
            continue;
        }
        <input type="checkbox" name="AttachmentIds" value="@item.Id" />@item.Name     
    }
    <br /><br />
    <input id="btnAdd" style="background-color:blue;color:white;width:100px;height:50px" type="button" value="添加" />
</form>
@section footerjs{
    <script type="text/javascript">
        $(function () {
            //小区与城市联动
            $('#quyu').change(function () {
                var regionId = $(this).val();
                $.ajax({
                    url: '/House/XiaoQuByRegionId/' + regionId,
                    type: 'post',
                    dataType: 'json',
                    success: function (res) {
                        var xiaoqu = $('#Community');
                        xiaoqu.html('');
                        for (var i = 0; i < res.length; i++) {
                            var str = '<option value=' + res[i].id + '>' + res[i].name + '</option>';
                            xiaoqu.append(str);
                        }
                    },
                    error: function () {
                        alert('网络请求错误');
                    }
                })
            })

            $('#btnAdd').click(function () {
                var fromData = $('#formData').serializeArray();
                $.ajax({
                    url: '/House/Edit',
                    data: fromData,
                    type: 'post',
                    dataType: 'json',
                    success: function (res) {
                        if (res.status == "ok") {
                            parent.location.reload();
                        }
                        else {
                            alert(res.errorMsg);
                        }
                    },
                    error: function () {
                        alert('网络请求错误');
                    }
                })
            })
        })
    </script>
}
